home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / nextpow2 < prev    next >
Text File  |  1995-02-19  |  659b  |  37 lines

  1. //-------------------------------------------------------------------//
  2. // Synopsis:    Next integer power of 2.
  3.  
  4. // Usage:       nextpow2 ( N )
  5.  
  6. // Description:
  7.  
  8. //      nextpow2 returns the first integer such tht 2^P >= N. If N is
  9. //      a vector, then nextpow2 computes P such that 2^P >= length(N).
  10.  
  11. // See Also: frexp
  12.  
  13. //-------------------------------------------------------------------//
  14.  
  15. nextpow2 = function ( n )
  16. {
  17.   local (n)
  18.  
  19.   if (length (n) > 1) 
  20.   {
  21.     n = length (n);
  22.   }
  23.  
  24.   </ e ; f /> = frexp (abs(n));
  25.   
  26.   //
  27.   // If e == 0.5, then the exponent is 1 > than the value we want.
  28.   //
  29.  
  30.   if (f == 0.5)
  31.   {
  32.     e = e - 1;
  33.   }
  34.  
  35.   return e;
  36. };
  37.